package com.example.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig  extends WebMvcConfigurationSupport {

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(JwtInterceptor())        // 注册拦截器
                .addPathPatterns("/**")                 // 拦截所有请求
                .excludePathPatterns("/login","/register");
        super.addInterceptors(registry);
    }


    @Bean
    public JwtInterceptor JwtInterceptor(){
        return new JwtInterceptor();
    }
}
